package com.cjz.roomdbdemo.db;

import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;

import java.util.List;

/**
 * 访问数据库接口
 * <p>
 * Created by cjz on 2018/8/31.
 */

@Dao
public interface NoteDAO {

    String databaseName = "note_database";
    String tableName = "note_table";

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(Note note);

    @Query("DELETE FROM " + tableName)
    void deleteAll();

    @Query("SELECT * from " + tableName + " ORDER BY insertTime DESC")
    LiveData<List<Note>> getAllNotes();

}
